"""empty message

Revision ID: f8aa756c44f9
Revises: 76c457093e38
Create Date: 2017-08-13 15:56:50.379092

"""

from alembic import op
import sqlalchemy as sa
import sqlalchemy_utils

from sqlalchemy import engine_from_config
# revision identifiers, used by Alembic.
revision = 'f8aa756c44f9'
down_revision = '76c457093e38'


def table_exists(table):
    config = op.get_context().config
    engine = engine_from_config(
        config.get_section(config.config_ini_section), prefix='sqlalchemy.')
    return engine.dialect.has_table(engine, table)


def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    if not table_exists('import_jobs'):
        op.create_table('import_jobs',
                        sa.Column('id', sa.Integer(), nullable=False),
                        sa.Column('task', sa.String(), nullable=False),
                        sa.Column('starts_at', sa.DateTime(timezone=True), nullable=True),
                        sa.Column('user_id', sa.Integer(), nullable=True),
                        sa.Column('result', sa.String(), nullable=True),
                        sa.Column('result_status', sa.String(), nullable=True),
                        sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
                        sa.PrimaryKeyConstraint('id')
                        )
    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    if table_exists('import_jobs'):
        op.drop_table('import_jobs')
    ### end Alembic commands ###
